<?php

/**
 * 
 * LinkElement model
 * 
 * @author Evan
 *
 */
class LinkElement extends Element
{
	private $url = '';
	private $text = '';
	private $target = '';
	
	public function __construct($id = NULL, $content = '', $order='', $content_id = '')
	{
		$this->id = $id;
		$this->content = $content;
		$this->order = $order;
		$this->content_id = $content_id;
		if (!empty($content))
		{
			$this->fetchDataFromContent();
		}
	}
	
	private function fetchDataFromContent()
	{
		try {
			$xmlContent = new SimpleXMLElement($this->content);
			$data = $xmlContent->children();
			$this->url = $data->url;
			$this->text = $data->text;
			$this->target = $data->target;
		}
		catch (Exception $e)
		{
			echo $e->getMessage();
		}
	}
	
	public static function getType()
	{
		return __CLASS__;
	}
		
	public function getURL()
	{
		return $this->url;
	}
	
	public function getText()
	{
		return $this->text;
	}
	
	public function getTarget()
	{
		return $this->target;
	}
	
	public function setURL($url)
	{
		$this->url = $url;
	}
	
	public function setText($text)
	{
		$this->text = $text;
	}
	
	public function setTarget($target)
	{
		$this->target = $target;
	}
	
	/**
	 * returns Content in XML-String
	 * 
	 * @see Element::getContent()
	 */
	public function getContent()
	{
		$linkElement = new SimpleXMLElement("<LinkElement></LinkElement>");
		$linkElement->addChild("url", $this->url);
		$linkElement->addChild("text", $this->text);
		$linkElement->addChild("target", $this->target);
		return $linkElement->asXML();
	}
	
}

?>